﻿using BLL;
using MODEL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Loginter
{
    public partial class UpdateTruckTeam : System.Web.UI.Page
    {
        //调用BLL层的车队信息
        TruckTeamBLL truckteam = new TruckTeamBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindUpdate();
            }
        }

        /// <summary>
        /// 修改按钮，修改车队的信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_update_Click(object sender, EventArgs e)
        {
            //将进行绑定的信息添加到buttonclick事件中运行
            //BindUpdate();

            //车队名称
            string tname = txt_name.Text.Trim();
            //负责人
            string lname = txt_Leader.Text.Trim();
            //备注
            string rt = txt_Remark.Text.Trim();
            string time = DateTime.Now.ToShortDateString();
            int id = Convert.ToInt32(Request.QueryString["sid"]);


            TruckTeamMODEL team = new TruckTeamMODEL()
            {
                TeamID = id,
                TeamName = tname,
                Leader = lname,
                Remark = rt,

                AlterTime = Convert.ToDateTime(time)
            };
            int result = truckteam.UpdateTruckTeam(team);
            if (result > 0)
            {
                //跳转页面到用户信息
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('修改成功！');location.href='TruckTeamInfo.aspx';</script>");
            }
            else
            {
                lb_Info.Text = "修改失败！";
            }
        }
        /// <summary>
        /// 绑定用户信息并修改信息
        /// </summary>
        private void BindUpdate()
        {
            //获取用户信息的id
            int id = Convert.ToInt32(Request.QueryString["sid"]);

            //调用model层的数据
            TruckTeamMODEL info = truckteam.GetUpdateTruckTeamDAL(id);
            if (info != null)
            {
                txt_name.Text = info.TeamName;
                txt_Leader.Text = info.Leader;
                txt_Remark.Text = info.Remark;


            }
        }
    }
}